﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 车牌识别系统1
{
    public partial class Form8 : Form
    {
        public Form8()
        {
            InitializeComponent();
        }

        private void label7_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
                string SqlStr = "server=.;database=cpsm;integrated security=SSPI";
                SqlConnection con = new SqlConnection(SqlStr);
                con.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection = con;
                comm.CommandText = "insert into table_4(tjz,btjz)  values('" + textBox1.Text + "','" + textBox2.Text + "');insert into table_3(userid,psw) select userid,psw from table_1 where userid='" + textBox2.Text + "'";
                if (textBox3.Text == label4.Text + label5.Text + label6.Text + label7.Text)
                {
                if (comm.ExecuteNonQuery() > 0)
                {
                    MessageBox.Show("添加成功", "正确", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    Form6 f6 = new Form6();
                    f6.Show();
                    this.Hide();
                }
                else

                    MessageBox.Show("添加失败！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                Random ran = new Random();
                label4.Text = ran.Next(10).ToString();
                label5.Text = ran.Next(10).ToString();
                label6.Text = ran.Next(10).ToString();
                label7.Text = ran.Next(10).ToString();
                textBox1.Clear();
                textBox2.Clear();
                textBox3.Clear();
                textBox1.Focus();
               }
                else
                MessageBox.Show("验证码不正确，请重新输入", "验证", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                textBox1.Clear();
                textBox2.Clear();
                textBox3.Clear();
                textBox1.Focus();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("是否取消添加？", "退出", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                Form7 f7 = new Form7();
                f7.Show();
            }
            else 
            {
                Form8 f8 = new Form8();
                f8.Show();
            }
        }

        private void toolStripStatusLabel1_Click(object sender, EventArgs e)
        {

        }

        private void Form8_Load(object sender, EventArgs e)
        {
            toolStripStatusLabel2.Text = "添加时间:" + DateTime.Now.ToLongTimeString();
            toolStripStatusLabel1.Text = "日期:" + DateTime.Now.ToShortDateString();
            Random ran = new Random();
            label4.Text = ran.Next(10).ToString();
            label5.Text = ran.Next(10).ToString();
            label6.Text = ran.Next(10).ToString();
            label7.Text = ran.Next(10).ToString();
        }

        private void label8_Click(object sender, EventArgs e)
        {
            Random ran = new Random();
            label4.Text = ran.Next(10).ToString();
            label5.Text = ran.Next(10).ToString();
            label6.Text = ran.Next(10).ToString();
            label7.Text = ran.Next(10).ToString();
        }
    }
}
